// https://leetcode.cn/problems/largest-number/
// Created by ade on 2022/8/24.
// 给定一组非负整数 nums，重新排列每个数的顺序（每个数不可拆分）使之组成一个最大的整数。

class Solution {
public:
    string largestNumber(vector<int> &nums) {
        sort(nums.begin(), nums.end(), [](int s1, int s2) {
            long sx = 10, sy = 10;
            while (sx <= s1) {
                sx *= 10;
            }
            while (sy <= s2) {
                sy *= 10;
            }
            return sy * s1 + s2 > sx * s2 + s1;
        });
        if (nums[0] == 0) {
            return "0";
        }
        string res = "";
        for (auto i: nums) {
            res += to_string(i);
        }
        return res;
    }
};